package com.teachoa.bean;

import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.teachoa.constant.Global;
import com.teachoa.util.DictUtil;

public class Course extends Model<Course> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4368447807161690297L;
	
	public static final Course dao = new Course();
	
	public Page<Course> findByPage(int pageNo) {
		Page<Course> coursePage = dao.paginate(pageNo, Global.pageSize, "select *"
				, "from course order by create_time desc");
		Map<Integer, String> dictMap = DictUtil.getDictMapByPath(Global.courseTypePath);
		for(Course course:coursePage.getList()) {
			String userId = course.getStr("user_id");
			User user = User.dao.findById(userId);
			course.put("user_name", user.getStr("username"));
			course.put("type_display", dictMap.get(course.getInt("type")));
		}
		return coursePage;
	}
	
	public List<Course> findAll() {
		return dao.find("select * from course");
	}

}
